package com.world.rickcloudendpoint.demo;

/**
 * @description: 消息配置
 * @author: jlsong
 * @date: 2022/03/17 21:27:32
 * @version: 1.0
 */
public class QueueConfig {
    private String queueName;
    private MsgConsumer consumer;

    public QueueConfig() {
    }

    public static Builder builder(){
        return new Builder();
    }

    public String getQueueName() {
        return queueName;
    }

    public MsgConsumer getConsumer() {
        return consumer;
    }

    public static class Builder{
        private QueueConfig config = new QueueConfig();

        public QueueConfig defaultConfig(MsgConsumer consumer){
            config.consumer = consumer;
            config.queueName = consumer.getClass().getSimpleName();
            return config;
        }

        public Builder queue(String queueName){
            config.queueName = queueName;
            return this;
        }

        public Builder consumer(MsgConsumer consumer){
            config.consumer = consumer;
            return this;
        }

        public QueueConfig build(){
            if (config.queueName == null || config.queueName.length() ==0 ){
                if (config.consumer != null){
                    config.queueName = config.getClass().getSimpleName();
                }
            }
            return config;
        }
    }
}
